Passed
Push — master ( eb1df1...2b6a8e )
by Felipe Catão do
01:59 queued 10s
created

index.js ➔ listPage   A

Complexity

Conditions 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 4
1
import EngineApp from '../../Framework/engine.js'
2
import cards from './components/cards.js'
3
import welcomeguide from './components/welcomeGuide.js'
4
import menu from './components/menu.js'
5
import error from './components/error.js'
6
import listCards from './components/listCards.js'
7
let eng = new EngineApp()
8
9
menu() //Render Menu 
10
eng.renderEngine.registerDinamicPage("dinamicType")
11
//Add rota
12
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/","initialPage")
13
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pageInitial",welcomeguide)
14
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pages/docs",docsPage)
15
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pages/docs/erro",error) 
16
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pages/docs/list",listPage) 
17
//para redirecionar a rota inicial
18
eng.routesEngine.runRoute("http://127.0.0.1:5500/project/index.html","http://127.0.0.1:5500/project/index.html#pageInitial")
19
20
//procurar paginação de documentos
21
function docsPage(){
22
    eng.renderEngine.clearPage()
23
    cards()
24
    if(eng.routesEngine.routePropsVars[0]!=undefined){
0 ignored issues
show
Best Practice introduced by
Comparing eng.routesEngine.routePropsVars.0 to undefined using the != operator is not safe. Consider using !== instead.
Loading history...
25
        Api(eng.routesEngine.routePropsVars[0])
26
    }
27
    else{
28
        eng.renderEngine.clearPage()
29
        error()
30
    }
31
}
32
//quando modificar o campo de  procura 
33
eng.routesEngine.whenChange(searchGuide,"searchGuide")
34
35
function searchGuide(){
36
   let searchArgs = document.getElementById("searchGuide").value.length
37
   if(searchArgs>0){
38
    eng.routesEngine.goToLink("http://127.0.0.1:5500/project/index.html#pages/docs="+searchArgs)
39
   }
40
   else{
41
       eng.renderEngine.clearPage()
42
       eng.routesEngine.goToLink("http://127.0.0.1:5500/project/index.html#pages/docs/erro")
43
   }
44
}
45
46
function listPage(){
47
    eng.renderEngine.clearPage()
48
    listCards()
49
    for (let index = 1; index < 20; index++) {
50
        fetch('https://jsonplaceholder.typicode.com/posts/' + index)
51
        .then(response => response.json())
52
        .then(json => eng.renderEngine.renderHtml("ListGroup","<li class='list-group-item'>"+json.title+"</li>"))
53
    }
54
}
55
56
document.getElementById("idHome").addEventListener("click",GoMainHome,false)
57
document.getElementById("listprod").addEventListener("click",listPage,false)
58
59
function GoMainHome(){
60
    eng.renderEngine.clearPage()
61
    eng.routesEngine.goToLink("http://127.0.0.1:5500/project/index.html#pageInitial")
62
}
63
64
//API
65
function Api(data) {  
66
    fetch('https://jsonplaceholder.typicode.com/posts/' + data)
67
        .then(response => response.json())
68
        .then(json => eng.renderEngine.changeContentElement("header0", json.title))
69
70
    fetch('https://jsonplaceholder.typicode.com/posts/' + data)
71
        .then(response => response.json())
72
        .then(json => eng.renderEngine.changeContentElement("contentBody", json.body))
73
}
74
75
let varLcoal=""
76
77
function HelloBase(name){
78
    varLcoal=name
79
    return ('<div> #{name} </div>')
80
}
81
82
function preRender(render){
83
    let varFunction = ""
84
    let varname=""
85
    let index=0
86
    while(render.length > index){
87
        if(render[index]=='#' && render[index+1]=='{'){
88
            while(render[index]!="}"){
89
                varFunction+=render[index]
90
                varname+=render[index]
91
                index++
92
            }
93
            if(render[index]=="}")varFunction+='}'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
94
        }
95
        index++
96
    }
97
    render = render.replace(varFunction,varLcoal)
98
    return render
99
}
100
101
function render(base){
102
103
    return preRender(base)
104
}
105
106
document.getElementById("idHome").append(render(HelloBase("ola")))